<template>
    <div class="goods-tabs">
        <nav>
            <a @click="activeName = 'goodsDetail'" :class="{active:activeName === 'goodsDetail'}"
                href="javascript:;">商品详情</a>
            <a @click="activeName = 'goodsComment'" :class="{ active: activeName === 'goodsComment' }"
                href="javascript:;">商品评价<span>{{ goods.commentCount }}</span></a>
        </nav>
        <!-- 切换内容的地方 -->
        <keep-alive>
            <transition name="fade" mode="out-in">
                <component :is="activeName"></component>
            </transition>
        </keep-alive>
    </div>
</template>
<script>
import { ref, inject } from 'vue'
import goodsDetail from './goods-detail.vue';
import goodsComment from './goods-comment.vue';
export default {
    name: 'GoodsTabs',
    components: {
        goodsDetail, goodsComment
    },
    setup() {
        const activeName = ref('goodsDetail')
        const goods = inject('goods')
        
        return {
            activeName,
            goods
        }
    }
}
</script>
<style lang="less">
.goods-tabs {
    min-height: 600px;
    background: #fff;

    nav {
        height: 70px;
        line-height: 70px;
        display: flex;
        border-bottom: 1px solid #f5f5f5;

        a {
            padding: 0 40px;
            font-size: 18px;
            position: relative;

            >span {
                color: @priceColor;
                font-size: 16px;
                margin-left: 10px;
            }

            &:first-child {
                border-right: 1px solid #f5f5f5;
            }

            &.active {
                &::before {
                    content: "";
                    position: absolute;
                    left: 40px;
                    bottom: -1px;
                    width: 72px;
                    height: 2px;
                    background: @xtxColor;
                }
            }
        }
    }
}

.fade-enter-from,
.fade-leave-to {
    opacity: 0;
    transform: translate3d(50px,20px,0);
}

.fade-enter-active,
.fade-leave-active{
    transition: all .5s;
}

.fade-enter-to,
.fade-leave-from {
    opacity: 1;
    transform: translate3d(0,0,0);
}
</style>